package com.bingo.mpa.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.bingo.mpa.pojo.Log;

public class LogDao
{
	public static void saveLog( Log obj ) throws SQLException
    {
		final Connection conn = ConnectionPool.getConnection();
		PreparedStatement pstmt = null;
		String sql = "INSERT INTO P_LOG(CLIENT_IP, TYPE, SEVERITY, LTIME, LTEXT)" + " VALUES(?, ?, ?, ?, ?)";
		conn.setAutoCommit(false);
        int j = 1;
        try
        {
        	pstmt = conn.prepareStatement(sql.toString());
        	pstmt.setString( j++, obj.getClient_ip());
        	pstmt.setByte(j++, obj.getType());
        	pstmt.setByte(j++, obj.getSeverity());
        	pstmt.setTimestamp(j++, obj.getLtime());
        	pstmt.setString(j++, obj.getLtext());
        	pstmt.execute();
        	conn.commit();
        }
        catch(Exception e)
        {
        	e.printStackTrace();
        }
        finally
        {
        	try
        	{
        		if(pstmt != null)pstmt.close();
        		if(conn != null)
        		{
        			conn.setAutoCommit(true);
        			conn.close();
        		}
        	}
        	catch(Exception ex)
        	{
        		ex.printStackTrace();
        	}
        }
    }
}
